package com.codi.bus.core.util;

import com.codi.base.util.StringUtil;
import com.codi.bus.constant.GlobalConstant;
import com.codi.bus.core.domain.User;
import com.codi.bus.core.resultModel.BaseResult;
import com.codi.message.constant.ErrorConstant;
import com.codi.message.util.MessageUtil;
import lombok.extern.slf4j.Slf4j;

/**
 * 模块名
 *
 * @author spy
 * @version 1.0 2017-11-30 14:13
 * @since 1.0
 */
@Slf4j
public final class BaseResultUtil {


    public static void parseErrMsg(BaseResult result) {
        if (result == null) {
            return;
        }

        if (result.getSuccess()) {
        } else {
            if (StringUtil.isEmpty(result.getErrorMessage())) {
                result.setErrorMessage(MessageUtil.getErrorMsg(result.getErrorCode()));
            }
        }
    }

    /**
     * 判断是否已开户
     */
    public static <T extends BaseResult> T isOpen(T t, User user) {
        if (user == null || StringUtil.isEmpty(user.getExternalClientId())) {
            t.setSuccess(false);
            t.setErrorMessage(MessageUtil.getErrorMsg(ErrorConstant.ERROR_NO_ACCOUNT));
            t.setErrorCode(ErrorConstant.ERROR_NO_ACCOUNT);
            t.setErrorType(GlobalConstant.ERROR_TYPE_APPLICATION);
            return t;
        } else {
            t.setSuccess(true);
            return t;
        }
    }
}
